package jehc.cloud.common.thread;

import java.util.List;
import jehc.cloud.common.base.BasePage;
import jehc.cloud.common.entity.ModifyRecordEntity;
import jehc.cloud.common.util.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;

/**
 * @Desc 统一字段变更记录日志
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Slf4j
public class ModifyRecordThread implements Runnable{
	private List<ModifyRecordEntity> recordList;
	private HttpServletRequest request;
	@Autowired
    RestTemplateUtil restTemplateUtil;
	//无参构造函数
	public ModifyRecordThread(){
	}
	//有参构造函数
	public ModifyRecordThread(List<ModifyRecordEntity> recordList){
		this.recordList = recordList;
	}
	//有参构造函数
	public ModifyRecordThread(List<ModifyRecordEntity> recordList,HttpServletRequest request){
		this.recordList = recordList;
		this.request = request;
	}

	public void addModifyRecord(HttpServletRequest request){
		try {
			if(null != recordList && recordList.size() > 0){
				log.info("开始记录变更日志");
				//兼容oracle 及mysql 语法 废弃批量
				for(ModifyRecordEntity modifyRecordEntity:recordList){
					restTemplateUtil.post(restTemplateUtil.restSysURL() + "/xtModifyRecord/add", BasePage.class, modifyRecordEntity, request);
				}
				log.info("变更记录日志结束");
			}
		} catch (Exception e) {
			log.error("变更记录失败，:"+recordList.toString()+"，异常：{}",e);
		}
	}

	@Override
	public void run() {
		try {
			addModifyRecord(request);
		} catch (Exception e) {
			log.error("记录变更记录失败，:"+recordList.toString()+"，异常：{}",e);
		}
	}
}
